package net.qiyuesuo.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.qiyuesuo.pojo.FileMeta;
import net.qiyuesuo.service.FileService;
import net.qiyuesuo.service.impl.FileServiceImpl;

/**
 * 获取文件信息接口
 * @author Administrator
 *
 */
public class GetFileInfoServlet extends HttpServlet{
	
	private static final long serialVersionUID = 1L;
	private Logger logger = LoggerFactory.getLogger(getClass());
	private FileService fileService = new FileServiceImpl();
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		String fileKey = req.getParameter("fileKey");
		try(ServletOutputStream output = res.getOutputStream();) {
			FileMeta fileInfo = fileService.getFileInfo(fileKey);
			output.write(fileInfo.toJson().getBytes());
			//返回信息
			output.flush();
			logger.info("获取uuid为："+fileKey+"的文件信息");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
